package com.yuedao.sender.service1;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.yuedao.sender.model.OperateArrive;
import com.yuedao.sender.model.OperateDepart;
import com.yuedao.sender.model.OperateLogin;
import com.yuedao.sender.model.OperateLogout;
import com.yuedao.sender.model.OperatePay;
import com.yuedao.sender.service.OperateArriveRepository;
import com.yuedao.sender.service.OperateDepartRepository;
import com.yuedao.sender.service.OperateLoginRepository;
import com.yuedao.sender.service.OperateLogoutRepository;
import com.yuedao.sender.service.OperatePayRepository;

import cn.ydx.protobuf.OTIpcDef;

@Service
public class OperateService extends BaseService {

	private String loginURL ="/operate/login";

	private String logoutURL = "/operate/logout";

	private String departURL = "/operate/depart";

	private String arriveURL = "/operate/arrive";

	private String payURL = "/operate/pay";

	/**
	 * A.6.1 车辆经营上线接口
	 */
	public String sendOperateLogin(List<OperateLogin> list) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.operateLogin);
			for (OperateLogin data : list) {
				builder.addOperateLogin(OperateLogin.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(loginURL, otIpc);
		}
		return null;
	}

	/**
	 * A.6.2 车辆经营下线接口
	 */
	public String  sendOperateLogout(List<OperateLogout> list) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.operateLogout);
			for (OperateLogout data : list) {
				builder.addOperateLogout(OperateLogout.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(logoutURL, otIpc);
		}
		return null;
	}

	/**
	 * A.6.3 经营出发接口
	 */
	public String sendOperateDepart(List<OperateDepart> list) {

		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.operateDepart);
			for (OperateDepart data : list) {
				builder.addOperateDepart(OperateDepart.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(departURL, otIpc);
		}
		return "error";
	}

	/**
	 * A.6.4 经营到达接口
	 */
	public String sendOperateArrive(List<OperateArrive> list) {

		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.operateArrive);
			for (OperateArrive data : list) {
				builder.addOperateArrive(OperateArrive.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(arriveURL, otIpc);
		}
		    return "";
	}

	/**
	 * A.6.5 经营支付接口
	 */
	public String  sendOperatePay(List<OperatePay> list) {
		
		if (list.size() > 0) {
			OTIpcDef.OTIpc.Builder builder = OTIpcDef.OTIpc.newBuilder()
					.setCompanyId(companyId).setSource(companySource)
					.setIPCType(OTIpcDef.IpcType.operatePay);
			for (OperatePay data : list) {
				builder.addOperatePay(OperatePay.convert(data));
			}

			OTIpcDef.OTIpc otIpc = builder.build();

			return super.compressAndSend(payURL, otIpc);
		}
		return null;
	}

}
